<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="sitemesh" uri="http://www.opensymphony.com/sitemesh/decorator" %>
<c:set var="ctx" value="${pageContext.request.contextPath}"/>
<%@ taglib prefix="tags" tagdir="/WEB-INF/tags" %>

<style type="text/css">
    .ui-datepicker-calendar {
        display: none;
    }

    .ui-datepicker select.ui-datepicker-month, .ui-datepicker select.ui-datepicker-year {
        width: 44%;
    }

    .tablewrapper table#example {
        width: 1024px !important;
    }

    .ui-progressbar {
        position: relative;
    }
    .progress-label-ie {
        position: absolute;
        left: 50%;
        top: 4px;

    }
</style>

<div class="panel_container">
    <div class="panel">
        <form id="formId" method="post" action="${ctx}/mbt/mbtImport">
            <div class="panel_header">
                <div><h2>导入修改</h2></div>
            </div>
            <div class="panel_body">
                <div>
                    <div>
                        <div class="info_item">
                            <font color=red size="5" ><b> 导入数据时，每次只能导入某一个月的数据</b></font>
                            <input type="hidden" id="tempType" name="tempType">
                        </div>
                        <div class="info_item">
                            <input type="button" value="查看导入数据历史" class="btn_blue" id="btn_back"/>
                        </div>
                    </div>
                    <div>
                        <div class="info_item"><span>导入贷款:</span><b>*</b>
                            <input type="file" id="importLoan" name="importfile" />
                            <a href="${ctx}/file/down?fileName=import-loan&systemType=temp">下载贷款模板</a>
                        </div>
                        <div class="info_item">

                        </div>
                        <div class="info_item">
                            <input type="button" value="导入" class="btn_blue" id="btn_saveLoan"  onclick="submitForm(23)"/>
                        </div>
                    </div>
                    <div>
                        <div class="info_item"><span>导入贴现:</span><b>*</b>
                            <input type="file" id="importDiscount" name="importfile" />
                            <a href="${ctx}/file/down?fileName=import-discount&systemType=temp">下载贴现模板</a>
                        </div>
                        <div class="info_item">
                            <input type="button" value="导入" class="btn_blue" id="btn_saveDiscount" onclick="submitForm(24)"/>
                        </div>
                    </div>
                    <div>
                        <div class="info_item"><span>导入银票:</span><b>*</b>
                            <input type="file" id="importDraft" name="importfile" />
                            <a href="${ctx}/file/down?fileName=import-drafts&systemType=temp">下载银票模板</a>
                        </div>
                        <div class="info_item">
                            <input type="button" value="导入" class="btn_blue" id="btn_saveDrafts" onclick="submitForm(25)"/>
                        </div>
                    </div>
                    <div>
                        <div class="info_item"><span>导入委托贷款:</span><b>*</b>
                            <input type="file" id="importFileEntrustedLoan" name="importfile" />
                            <a href="${ctx}/file/down?fileName=import-entrustedLoan&systemType=temp">下载委托贷款模板</a>
                        </div>
                        <div class="info_item">
                            <input type="button" value="导入" class="btn_blue" id="btn_saveEntrustedLoan" onclick="submitForm(26)"/>
                        </div>
                    </div>
                    <div>
                        <div id="progressbar" style="display:none"><div class="progress-label-ie">加载。。。</div></div>
                        <div ><div id="message"></div></div>
                    </div>
                </div>
            </div>
            <div class="panel_footer">

            </div>
        </form>
    </div>
</div>

<script type="text/javascript">

    function refreshPage(){
        linkTo("${ctx}/mbt/toExport");
    }

    function submitForm(type){
        var message;
        var flag=true;
        $("#tempType").val(type);
        if(type=="23"){
            if($("#importLoan").val()==""){
                message="贷款附件不能为空";
                flag=false;
            }
            $("#importDiscount").val("");
            $("#importDraft").val("");
            $("#importFileEntrustedLoan").val("");
        }else if(type=="24"){
            if($("#importDiscount").val()==""){
                message="贴现附件不能为空"
                flag=false;
            }
            $("#importLoan").val("");
            $("#importDraft").val("");
            $("#importFileEntrustedLoan").val("");
        }else if(type=="25"){
            if($("#importDraft").val()==""){
                message="银票附件不能为空"
                flag=false;
            }
            $("#importLoan").val("");
            $("#importDiscount").val("");
            $("#importFileEntrustedLoan").val("");
        }else if(type=="26"){
            if($("#importFileEntrustedLoan").val()==""){
                message="委托贷款附件不能为空"
                flag=false;
            }
            $("#importLoan").val("");
            $("#importDiscount").val("");
            $("#importDraft").val("");
        }
        if(flag){
            $("#formId").submit();
        }else{
            $.prompt("附件必选:"+message);
        }
    }

    function goBack(){
        linkTo("${ctx}/mbt/toHistory");
    }

    $(function () {
        var data="";
        var progressbar = $( "#progressbar" ),
                progressLabel = $( ".progress-label-ie" );

        progressbar.progressbar({
            value: false,
            change: function() {
                progressLabel.text( progressbar.progressbar( "value" ) + "%" );
            },
            complete: function() {
                progressLabel.text( "完成！" );
                $("#message").empty();
                var  resultMessage =data.split("===") ;
                $("#message").append("查看详细返回信息");
                for(var i=0;i<resultMessage.length-1;i++){
                    $("#message").append("<br>");
                    $("#message").append(i+1).append(". ").append(resultMessage[i]);

                }

                $("#btn_refresh").show();
                $("#btn_save").hide();
            }
        });

        function progress() {
            var val = progressbar.progressbar( "value" ) || 0;
            progressbar.progressbar( "value", val + 1 );
            if ( val < 99 ) {
                setTimeout( progress, 100 );
            }
        }


        $("#btn_back").bind("click",goBack);
        $("#btn_save").bind("click",submitForm);


        $("#formId").validate({
            submitHandler: function(form) {
                $(form).ajaxSubmit({
                    beforeSubmit:function(){
                        $("#progressbar").show();
                    },
                    success: function (response) {
                        data = $.parseJSON(response).message;
                        progress();
                    },
                    error: function(data){
                        $.prompt("上传失败:"+data,"错误");
                    }
                });
            }
        });
    });

</script>

